<?php

namespace App\Models;

use App\Constants\Enum;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

/**
 * Copyright (C), 2021-2021, old_liu_cms.
 * FileName: User.php
 * Description: 用户信息
 *
 * @author old_liu_cms
 * @Create Date    2021/10/9 14:36
 * @Update Date    2021/10/9 14:36 By old_liu_cms
 * @version v1.0
 */
class  User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    /**
     * FunctionName：getJWTIdentifier
     * Description：
     * Author：old_liu_cms
     * @return mixed
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    /**
     * FunctionName：getJWTCustomClaims
     * Description：
     * Author：old_liu_cms
     * @return array
     */
    public function getJWTCustomClaims()
    {
        return [];
    }

    /**
     * @var string[]
     */
    protected $fillable = [
        'sex',
        'city',
        'head_img',
        'password',
        'nickname',
        'user_name',
        'created_at',
        'updated_at',
    ];

    /**
     * @var string[]
     */
    protected $hidden = [
        'password',
    ];

    /**
     * @var string[]
     */
    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * @var string[]
     */
    protected $appends = [
        'sex_str',
    ];

    /**
     * FunctionName：getSexStrAttribute
     * Description：性别
     * Author：old_liu_cms
     * @return string|null
     */
    public function getSexStrAttribute()
    {
        return Enum::USER_SEX[$this->sex] ?? null;
    }

    public static function edit(int $id, array $params)
    {
        return self::query()->whereKey($id)->update($params);
    }
}
